import { defineComponent, reactive, onMounted, ref ,computed} from "vue";
import { dxget, qurl } from "../../util/index";
import ecahrData from "../../util/ecahrData";
import store from "../../store";
import stock from "../../store/stock";
export default defineComponent({
  props: {
    types: {
      type: String, 
      default: "",
    },
    code: {
      type: String,
      default: "",
    },
  }, 
  setup(props) {
    const echarDxer = ref(null);
    let charDada = new ecahrData();
    const zf=ref()
    const currentTime = computed(() => {
      const newDate = new Date();
      const Hours = newDate.getHours();
      const myddy = newDate.getDay(); //获取存储当前日期
      /*每天的15点以后 和9点前 周六和周天 不刷新 */
      console.log(myddy);
      if (Hours > 15 || Hours < 8 || myddy == 6 || myddy == 0) {
        return;
      }
      initData(true);
      return store.state.currentTime;
    });
    const initData = async (ty)=>{
      let res: any = await dxget("czsc/index", {
        code: props.code,
      });
      let option = charDada.setDateLine(res.data.klines,ty);
      var myChart = window.echarts.init(document.getElementById("echarDxer"));
      console.log(ty);
      if(ty){
        let seriesData = []
        res.data.klines.map(a => {
          seriesData.push([a[1], a[2], a[4], a[3], a[5], a[7], a[8], a[9]])
        })
        let inf:any = stock.state.gpinfo
        
        let jhjkswe = Math.ceil(Math.random()*30);
        seriesData[seriesData.length-1][1]  = inf.f43
    
        myChart.setOption({
          series: [{
              data: seriesData
          }]
      });
      }else{
        myChart.setOption(option);
      }
     
 
      // let max = parseFloat(option.max)
      // let min =  parseFloat(option.min)
      //  zf.value = (((max-min)/min)*100).toFixed(2);
    }
    initData(false);
    return () => (
      <>
      <div class="pr h100">
        <span class="red dfdrttee">最大振幅{zf.value}%</span>
      <div class="echarDx" id="echarDxer" data-currentTime={currentTime.value}></div>
      </div>
       
      </>
    );
  },
});
